package demo3;


//实现一个简单的控制台版用户登陆程序,
// 程序启动提示用户输入用户名密码. 如果用户名密码出错, 使用自定义异常的方式来处理

import java.util.Scanner;

public class LogIn {

    private String password = "123456";

    public  void loginInfo(String password) throws PasswordException{

        if (!this.password.equals(password)) {
            throw new PasswordException("用户名错误！");
        }
        System.out.println("登陆成功");
    }
    public static void main(String[] args) {
        LogIn logIn = new LogIn();
        System.out.println("请输入用户名密码: ");
        Scanner scanner = new Scanner(System.in);
        String password = scanner.nextLine();
        try {
            logIn.loginInfo(password);
        } catch (PasswordException e) {
            e.printStackTrace();
        }
    }
}

/*class UserNameException extends Exception {
    public UserNameException(String message) {
        super(message);
    }
}
class PasswordException extends Exception {
    public PasswordException(String message) {
        super(message);
    }
}*/
